﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;

namespace Ken_WPF_UI.Model
{
    public class RelayCommand : ICommand
    {
        public event EventHandler CanExecuteChanged;
        public Action<object> executeAction;
        public Func<object,bool> canExecuteFunc;

        public RelayCommand()
        {
        }

        public RelayCommand(Action<object> execute):this(execute,null)
        {       
        }

        public RelayCommand(Action<object> execute, Func<object, bool> canExecute)
        {
            this.executeAction = execute;
            this.canExecuteFunc = canExecute;
        }

        public bool CanExecute(object parameter)
        {
            if (this.canExecuteFunc == null)
            {
                return true;
            }

            return this.canExecuteFunc(parameter);
        }

        public void Execute(object parameter)
        {
            if (this.executeAction == null)
            {
                return ;
            }
            this.executeAction(parameter);
        }
    }
}
